#ifndef _PLAYER_H_
#define _PLAYER_H_

#include <string.h>
#include "Item.h"
#include <vector>
#include "Net.h"

namespace car
{

#define		kMaxPlayerNameLength	32
#define		kMaxPasswordLength		32

typedef enum {
	PlayerStateNone,
	PlayerStateLoggingIn,
	PlayerStateLoggingOut,
	PlayerStateInHall, 
	PlayerStateCreatingRoom, 
	PlayerStateEnteringRoom,
	PlayerStateInRoom, 
	PlayerStateLeavingRoom,
	PlayerStateStartingGame,
	PlayerStateLoadingGame,
	PlayerStateLoadingGameComplete,
	PlayerStateInGame,
	PlayerStateGameEnd
}PlayerState;

typedef enum {
	GameResultDraw,
	GameResultWin,
	GameResultLose	
}GameResult;

class Room;

typedef struct
{
	unsigned int	timeStamp;
	float			posX;
	float			posY;
	float			velX;
	float			velY;
	unsigned int	appearance;
	unsigned int	score;	
	unsigned int	itemInUse;
	unsigned char	itemOne;
	unsigned char	itemTwo;
}PlayerAttribute;

class Player
{
public:
	Player( void );
	Player( unsigned int playerId );
	~Player( void );

	void			setPlayerId( unsigned int playerId ){ mPlayerId = playerId; }
	unsigned int	getPlayerId() const					{ return mPlayerId; }

	void	getPlayerName( char * name, unsigned int * size );
	void	setPlayerName( const char * name, unsigned int size );
	int		getPlayerNameSize()	const					{ return mPlayerNameSize; }

	void		setPlayerState( PlayerState state )	{ mState = state; }
	PlayerState	getPlayerState() const				{ return mState; }

	void			setRoomId( unsigned int roomId )	{ mRoomId = roomId; }
	unsigned int	getRoomId() const					{ return mRoomId; }

	void			setForceId( unsigned char forceId )	{ mForceId = forceId; }
	unsigned char	getForceId() const					{ return mForceId; }

	void	setPosX( float x )		{ mAttribute.posX = x; }
	float	getPosX() const			{ return mAttribute.posX; }
	void	setPosY( float y )		{ mAttribute.posY = y; }
	float	getPosY() const			{ return mAttribute.posY; }

	void	setVelX( float x )		{ mAttribute.velX = x; }
	float	getVelX() const			{ return mAttribute.velX; }
	void	setVelY( float y )		{ mAttribute.velY = y; }
	float	getVelY() const			{ return mAttribute.velY; }

	void			setAppearance( unsigned int appearance )	{ mAttribute.appearance = appearance; }
	unsigned int	getAppearance()								{ return mAttribute.appearance; }
	void			setItemOne( unsigned char itemId )			{ mAttribute.itemOne = itemId; }
	unsigned char	getItemOne()								{ return mAttribute.itemOne; };
	void			setItemTwo( unsigned char itemId )			{ mAttribute.itemTwo = itemId; }
	unsigned char	getItemTwo()								{ return mAttribute.itemTwo; }

	void			setTimeStamp( unsigned int timeStamp )		{ mAttribute.timeStamp = timeStamp; }
	unsigned int	getTimeStamp()								{ return mAttribute.timeStamp; }

	void			setScore( int score )						{ mScore = score; }
	int				getScore()									{ return mScore; }

	void			setGameResult( GameResult result )			{ mGameResult = result; }
	GameResult		getGameResult()								{ return mGameResult; }

	void			setLoadingProgress( unsigned int lprog )	{ mLoadingProgress = lprog; }
	unsigned int	getLoadingProgress()						{ return mLoadingProgress; }

	void	enterRoom( unsigned int roomId );
	void	leaveRoom();

	void	updateGamePlayStates( const PlayerAttribute & attr );

	void			setConnection( ReliableConnection & conn )	{ mConnection = conn; }
	bool			startConnection( unsigned short port )		{ return mConnection.start( port ); }
	void			setAddress( LASAddress & addr )				{ mConnection.setAddress( addr ); }

	bool	sendPacket( const unsigned char data[], int size );
	int		receivePacket( unsigned char data[], int size );

	bool	isPacketSent()						{ return mPacketSent; }
	void	setPacketSent( bool packetSent )	{ mPacketSent = packetSent; }

	void	resetStates();

	void	setCorrection( bool correction )	{ mCorrection = correction; }
	bool	getCorrection()						{ return mCorrection; }
	/*bool	operator==( const Player & player )
	{
		if( mPlayerId == player.getPlayerId() )
			return true;
		return false;
	}*/

private:
	PlayerState		mState;
	unsigned int	mPlayerId;
	char			mPlayerName[kMaxPlayerNameLength];
	unsigned int	mPlayerNameSize;
	unsigned int	mRoomId;
	unsigned char	mForceId;
	PlayerAttribute	mAttribute;
	unsigned int	mLoadingProgress;
	ReliableConnection	mConnection;
	bool			mPacketSent;
	unsigned int	mScore;
	GameResult		mGameResult;
	bool			mCorrection;
};

};

#endif